using System;
using System.Configuration;

namespace SoftwareMonkeys.Scriptech.Stores
{
	public class StoreReader
	{
		
		public static StoreCollection GetStores ()
		{
			StoreCollection stores = new StoreCollection();
			
			string[] rootDirectoryItems = ConfigurationSettings.AppSettings["Projects.RootPaths"].Trim (';').Split (';');
			
			foreach (string item in rootDirectoryItems) {
				string[] parts = item.Split ('=');
				
				if (parts.Length < 2)
					throw new Exception ("Invalid root directory item: " + item);
				
				string title = parts[0];
				string rootDirectory = parts[1];
				
				Store store = StoreCreator.New(title, rootDirectory);
				
				stores[title] = store;
			}
			
			return stores;
			
		}
		
		public static Store GetStore(string storeName)
		{
			return GetStores()[storeName];
		}
	}
}

